Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats: Improved sequencing documentation for server-side stats events and added tests. #7885

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

RyanBlaney
Copy link

Response to Issue #7824

RELEASE NOTES:

  • Documentation Clarification: Clarified the expected sequencing of stats events in the server-side stats.Handler.
  • New Test Cases: Added tests to verify the event sequencing for various RPC types, ensuring consistency and accuracy in server-side stats handling.

…s to verify the order of server-side events.
@RyanBlaney RyanBlaney changed the title Documentation, Test: Improved sequencing documentation for server-side stats events and added tests. *: Improved sequencing documentation for server-side stats events and added tests. Dec 2, 2024
Copy link

codecov bot commented Dec 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.09%. Comparing base (4c07bca) to head (ebecb99).
Report is 41 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7885      +/-   ##
==========================================
+ Coverage   81.84%   82.09%   +0.24%     
==========================================
  Files         377      381       +4     
  Lines       38120    38539     +419     
==========================================
+ Hits        31201    31639     +438     
+ Misses       5603     5582      -21     
- Partials     1316     1318       +2     
Files with missing lines Coverage Δ
stats/stats.go 68.42% <ø> (ø)

... and 59 files with indirect coverage changes

@RyanBlaney RyanBlaney marked this pull request as ready for review December 2, 2024 03:13
@arjan-bal arjan-bal changed the title *: Improved sequencing documentation for server-side stats events and added tests. stats: Improved sequencing documentation for server-side stats events and added tests. Dec 2, 2024
@arjan-bal arjan-bal self-requested a review December 2, 2024 09:25
@arjan-bal arjan-bal self-assigned this Dec 2, 2024
@arjan-bal arjan-bal added the Type: Documentation Documentation or examples label Dec 2, 2024
@arjan-bal arjan-bal added this to the 1.69 Release milestone Dec 2, 2024
Comment on lines 153 to 156
func (s *testServer) UnaryCall(
ctx context.Context,
in *testpb.SimpleRequest,
) (*testpb.SimpleResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grpc-go follows the Google style guide. Based on this section in the style guide:

The signature of a function or method declaration should remain on a single line to avoid indentation confusion.

Please revert the changes made to wrap function definationations and calls throughout the PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! I'll disable my autoformatter going forward or reconfigure it to follow the Google style guide.

@@ -786,8 +884,14 @@ func checkConnEnd(t *testing.T, d *gotData) {
st.IsClient() // TODO remove this.
}

type event struct {
eventType string
timestamp time.Time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use of storing a timestamp? I believe we're only interested in the ordering of the events and not the absolute times they were emitted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timestamp was included for debugging purposes in case of test failures, since it could help identify delays or other issues. If you feel this isn’t valuable, I can to remove it for simplicity.

@RyanBlaney
Copy link
Author

I have fixed the wrapping errors for formatting and I removed the timestamps from the event structs. Thank you for your feedback @arjan-bal, is there anything else you need me to do?

…. Added a server stats Server Stream RPC test.
@arjan-bal arjan-bal assigned arjan-bal and unassigned RyanBlaney Dec 3, 2024
@purnesh42H purnesh42H assigned purnesh42H and unassigned arjan-bal Dec 3, 2024
@arjan-bal arjan-bal requested review from purnesh42H and arjan-bal and removed request for arjan-bal December 3, 2024 08:01
@purnesh42H purnesh42H modified the milestones: 1.69 Release, 1.70 Release Dec 5, 2024
stats/stats.go Outdated Show resolved Hide resolved
stats/stats.go Show resolved Hide resolved
stats/stats_test.go Outdated Show resolved Hide resolved
@@ -81,6 +83,55 @@ var (
}
// The id for which the service handler should return error.
errorID int32 = 32202

// Server Stats
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the documentation everywhere. Remove extra spaces at start and end etc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything should be resolved now. Thank you for your help!

@RyanBlaney
Copy link
Author

I fixed the autoformatting mistakes and cleaned up the comments. I will not use an autoformatter going forward, since it caused me a headache. Is there anything else needed in terms of testing?

@purnesh42H purnesh42H assigned purnesh42H and unassigned RyanBlaney Dec 21, 2024
@purnesh42H
Copy link
Contributor

I fixed the autoformatting mistakes and cleaned up the comments. I will not use an autoformatter going forward, since it caused me a headache. Is there anything else needed in terms of testing?

Thanks, I will take a look. Looks like you have some vet check failures. Could you run the vet check locally and fix https://github.com/grpc/grpc-go/blob/master/CONTRIBUTING.md ?

@RyanBlaney
Copy link
Author

The vet errors should be fixed now. Happy holidays!

@RyanBlaney
Copy link
Author

I'm still failing one test for some reason. I didn't see that locally. I'll look into it when I get the chance.

stats/stats.go Outdated
@@ -36,7 +36,10 @@ type RPCStats interface {
IsClient() bool
}

// Begin contains stats when an RPC attempt begins.
// Begin contains stats when an RPC attempt begins. This event is called after
// the InHeader event, as headers must be processed before the RPC lifecycle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit InHeader

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What specifically is the issue here? Is it related to style?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Names from code should preferably be within backticks

stats/stats.go Outdated
@@ -98,7 +101,9 @@ func (s *InPayload) IsClient() bool { return s.Client }

func (s *InPayload) isRPCStats() {}

// InHeader contains stats when a header is received.
// InHeader contain stats when the header is received. It is the first event in
// the server after receiving the RPC. It is followed by the OutPayload
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OutPayload

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify what you are asking for here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Names from code should preferably be within backticks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, isn't it followed by Begin?

@@ -81,6 +81,50 @@ var (
}
// The id for which the service handler should return error.
errorID int32 = 32202
// To verify if the Unary RPC server stats events are logged in the
// correct order.
expectedUnarySequence = []string{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be initialized within the test itself because we are not using it anywhere else. Also, convention is to use want/wanted instead of expected

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! I will keep this in mind going forward. Thank you!

stats/stats_test.go Outdated Show resolved Hide resolved
stats/stats_test.go Outdated Show resolved Hide resolved
stats/stats_test.go Outdated Show resolved Hide resolved
stats/stats_test.go Outdated Show resolved Hide resolved
stats/stats_test.go Outdated Show resolved Hide resolved
@purnesh42H purnesh42H assigned RyanBlaney and unassigned purnesh42H Dec 26, 2024
Copy link
Contributor

@purnesh42H purnesh42H left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking close to LGTM. Few last set of comments.

stats/stats.go Outdated
@@ -98,7 +101,9 @@ func (s *InPayload) IsClient() bool { return s.Client }

func (s *InPayload) isRPCStats() {}

// InHeader contains stats when a header is received.
// InHeader contain stats when the header is received. It is the first event in
// the server after receiving the RPC. It is followed by the OutPayload
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, isn't it followed by Begin?

switch s.(type) {
case *stats.Begin:
h.recordEvent("Begin")
case *stats.InHeader:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be InHeader should be first case to be consistent with the order of occurence

gotEventTypes[i] = e.eventType
}
if !cmp.Equal(gotEventTypes, expected) {
t.Errorf("Event sequence mismatch (-got +expected):\n%s", cmp.Diff(gotEventTypes, expected))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/expected/want

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diff (-got +expected) since you are showing the diff

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming by added the vim command you want me to replace all occurrences of 'expected.'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is followed by Begin for server-side stats events. It follows the OutPayload for client-side events. I need to clarify this.


// verifyEventSequence verifies that a sequence of recorded events matches
// the expected sequence.
func verifyEventSequence(t *testing.T, got []event, expected []string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/expected/want

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are lines that I didn't write that contain the word 'expected.' Should those be changed too?

type statshandler struct {
mu sync.Mutex
events []event
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like we just need list of event types? Can't we directly use []string?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that should suffice.

@arjan-bal arjan-bal requested review from arjan-bal and removed request for arjan-bal January 13, 2025 17:30
Copy link
Contributor

@arjan-bal arjan-bal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unblocking for other reviewers to approve.

arjan-bal
arjan-bal previously approved these changes Jan 13, 2025
@arjan-bal arjan-bal requested review from arjan-bal and removed request for arjan-bal January 13, 2025 17:31
Copy link
Contributor

@arjan-bal arjan-bal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo approval.

@arjan-bal arjan-bal dismissed their stale review January 13, 2025 17:33

Approved while trying to remove the change request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Documentation Documentation or examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants